import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class CoreNoticeService extends BaseService<any> {
  private readonly logger = new Logger(CoreNoticeService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * send
   * 对应 PHP: NoticeService_core::send()
   * 逻辑类型: undefined - undefined
   */
  async send(site_id: any, key: any, data: any) {
    // 基于PHP真实逻辑: send
    // PHP原文: try {             $template = (new CoreNoticeService())->getInfo($site_id, $key);             Log::write("消息发送");             Log::write($template);  ...
try {
            const template = this.coreNoticeService.getInfo(site_id, key];
            Log.write("消息发送"];
            Log.write(template);
            if (!template)) return false;

            return Notice.dispatch([site_id: site_id, key: key, data: data, template: template), is_async: template.async];
  }
}
